﻿
Partial Class Tools_t
    Inherits MyUI.PageBaseApp



    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Response.BufferOutput = False

        Dim TTlist As List(Of MyApp.Task.ScheduleTask) = Application("task")

        If UI.Page.GetValue("r") <> "" Then
            If TTlist IsNot Nothing Then
                For Each TT In TTlist
                    TT.StopTask()
                Next
                TTlist.Clear()
                TTlist = Nothing
                UI.Page.WriteLog(SF("TASK STOP"))

            End If
            Application("task") = Nothing
            UI.Page.WriteLog(SF("TASK ELIMINATI"))


            Exit Sub

        End If

        UI.Page.WriteLog(SF(Integer.MaxValue))

        If TTlist Is Nothing Then

            TTlist = New List(Of MyApp.Task.ScheduleTask)


            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.UPDATE_ACCOUNTS.ToString,
                .SecondInterval = 20 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_UPDATE_ACCOUNTS/tools/update.aspx?a=1")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.SEND_POSTS.ToString,
                .SecondInterval = 1 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_SEND_POSTS/tools/update.aspx?a=3")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.UPDATE_POSTS.ToString,
                .SecondInterval = 15 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_UPDATE_POSTS/tools/update.aspx?a=5")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.UPDATE_QUERY.ToString,
                .SecondInterval = 5 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_UPDATE_QUERY/tools/update.aspx?a=2")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.ELABORATE_DATA.ToString,
                .SecondInterval = 60 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_ELABORATE_DATA/tools/update.aspx?a=4")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.INDEX_DATA.ToString,
                .SecondInterval = 60 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_INDEX_DATA/tools/update.aspx?a=9")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.AUTO_FOLLOW.ToString,
                .SecondInterval = 30 * 60,
                .Uri = New Uri("http://data.glouk.it/Data_AUTO_FOLLOW/tools/update.aspx?a=6")
            })


            'BETA
            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.UPDATE_ACCOUNTS.ToString & " [BETA]",
                .SecondInterval = 20 * 60,
                .Uri = New Uri("http://beta.glouk.it/tools/update.aspx?a=1")
            })

            TTlist.Add(New MyApp.Task.ScheduleTask With {
                .Label = MyApp.Task.TaskType.SEND_POSTS.ToString & " [BETA]",
                .SecondInterval = 1 * 60,
                .Uri = New Uri("http://beta.glouk.it/tools/update.aspx?a=3")
            })


            For Each tt In TTlist
                tt.start()
            Next


            Application("task") = TTlist

            UI.Page.WriteLog(SF("TASK CREATI"))

        Else

            UI.Page.WriteLog(SF("TASK NON CREATI, GIA ATTIVI"))

        End If

        UI.Page.WriteLog(SF("TASK ATTIVI"))

        For Each tt In TTlist
            UI.Page.WriteLog(SF("--- {0}, execute: {2}, interval: {1}", tt.Label, tt.SecondInterval, tt.Execute))
        Next

        UI.Page.WriteLog(SF("TASK DB"))

        For Each tt In DB.TAB.Schedule_Task.ToList
            UI.Page.WriteLog(SF("--- {0} - {1} - {2} - {3} - {4}", tt.Name, tt.Status, tt.Start_Date, tt.Stop_Date, tt.Last_Result))
        Next


        'Dim tt2 As New Task With {.SecondInterval = 5, .Uri = New Uri("http://www.facebook.com")}

        'tt2.start()



    End Sub



End Class

